package cn.wzptsoft.mall.handler;

import com.alibaba.fastjson.JSONObject;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

//从未生效
@Slf4j
public class AuthenticationFailure implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {


            System.out.println("---------------------------------------------------------------AuthenticationFailure");
            log.info("用户未登录成功");
            InternalAuthenticationServiceException exception = (InternalAuthenticationServiceException) e;
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().println("AuthenticationFailure错误信息：" + exception.getLocalizedMessage());

    }
}
